<%@ page import="schoolsource.gui.FormFields" %>
<%@ page import="schoolsource.security.SecurityToken" %>
<% 
	SecurityToken st = (SecurityToken) request.getAttribute(FormFields.SESSION); 
	String indentation = "&nbsp;&nbsp;&nbsp;&nbsp;";
    String requestObject = (String) st.getValue(FormFields.TOKEN);
	int editorPage = (new Integer((String) st.removeValue(FormFields.EDITORPAGE))).intValue();
	String loginType = (String) request.getAttribute(FormFields.USRTYPE); 
	String schoolName = (String) request.getAttribute(FormFields.SCHOOLNAME);
%>


<HTML>
  <HEAD>
    <SCRIPT>

    function validateNewPasswords() {
    	
    	var newPassword1 = document.forms[0].<%= FormFields.NEWPASSWORD %>.value;
    	var newPassword2 = document.forms[0].<%= FormFields.RENEWPASSWORD %>.value;
    	
    	if (newPassword1 == "") {
    		alert("You did not specify a password");
    		document.forms[0].<%= FormFields.NEWPASSWORD %>.focus();
    		return false;
    	}
    	else if (newPassword1 != newPassword2) {
    		alert("The new passwords you entered do not match.\nPlease re-enter your new password in both fields.");
    		document.forms[0].<%= FormFields.NEWPASSWORD %>.focus();
    		return false;
    	}
    	else {
    		return true;
    	}
    	
    }
    
    function postProcessing(value) {
        if (value == "Cancel") {
            changepasswordform.<%= FormFields.LINKCLICKED %>.value = value;
            changepasswordform.submit();
        }
        else if (validateNewPasswords()) {
            document.forms[0].<%= FormFields.LINKCLICKED %>.value = value;
            document.forms[0].submit();
        }
    }
    
    </SCRIPT>
  </HEAD>
  <BODY>
    <H3>Change Password for Administrator</H3>
    <FORM NAME="changepasswordform" METHOD="POST" onSubmit="return false;">
		<INPUT TYPE="HIDDEN" NAME="<%= FormFields.CURRENT %>" VALUE="<%= FormFields.SUBFRAME %>">
		<INPUT TYPE="HIDDEN" NAME="<%= FormFields.TOKEN %>" VALUE="<%= requestObject %>">
		<INPUT TYPE="HIDDEN" NAME="<%= FormFields.PARAMETER %>" VALUE="">
		<INPUT TYPE="HIDDEN" NAME="<%= FormFields.EDITORPAGE %>" VALUE="<%= editorPage %>"> 
		<INPUT TYPE="HIDDEN" NAME="<%= FormFields.LINKCLICKED %>" VALUE="<%= editorPage %>"> 
		<INPUT TYPE="HIDDEN" NAME="<%= FormFields.SCHOOLNAME %>" VALUE="<%= schoolName %>">
		<INPUT TYPE="HIDDEN" NAME="<%= FormFields.USRTYPE %>" VALUE="<%= loginType %>">

    <% 
        out.println("<TABLE WIDTH=\"400\"");
        out.println("  <TR>");
        out.println("    <TD WIDTH=\"200\"><B>Enter current password:&nbsp;&nbsp;</B>" + indentation + "</TD><TD WIDTH=\"200\"><INPUT TYPE=\"PASSWORD\" NAME=\"" + FormFields.CURRENTPASSWORD + "\"></TD>");
        out.println("  </TR>");
        out.println("  <TR>");
        out.println("    <TD WIDTH=\"200\"><B>Enter new password:&nbsp;&nbsp;</B>" + indentation + "</TD><TD WIDTH=\"200\"><INPUT TYPE=\"PASSWORD\" NAME=\"" + FormFields.NEWPASSWORD + "\"></TD>");
        out.println("  </TR>");
        out.println("  <TR>");
        out.println("    <TD WIDTH=\"200\"><B>Re-enter new password:&nbsp;&nbsp;</B>" + indentation + "</TD><TD WIDTH=\"200\"><INPUT TYPE=\"PASSWORD\" NAME=\"" + FormFields.RENEWPASSWORD + "\"></TD>");
        out.println("  </TR>");
        out.println("</TABLE>");
        out.println("<CENTER><INPUT TYPE=\"BUTTON\" NAME=\"" + FormFields.BUTTONCLICKED + "\" VALUE=\"Change Password\" onClick=\"postProcessing('Change Password');\">" + indentation);
        out.println("<INPUT TYPE=\"BUTTON\" NAME=\"" + FormFields.BUTTONCLICKED + "\" VALUE=\"Cancel\" onClick=\"postProcessing('Cancel');\"></CENTER>");
    %>
    </FORM>
  </BODY>
</HTML>